<?php
class Application_Model_Company
{
	protected $_dbTable;
	public $_mId;
	public $_mCode;
	public $_mStockExchange;
	public $_mCurrentPrice;
	public $_mBookValue;
	public $_mPB;
	public $_mHighest52w;
	public $_mLowest52w;
	public $_mEPS;
	public $_mPE;
	public $_mEPS4q;
	public $_mPE4q;
	public $_mROA;
	public $_mROE;
	public $_mFinancialLeverage;
	public $_mBeta;
	public $_mOutstandingShares;
	public $_mListedShares;
	public $_mTreasuryStock;
	public $_mNuocNgoaiSoHuu;
	public $_mVonThiTruong;
	public $_mRevenue;
	public $_mNPAT;
	public $_mEquity;
	public $_mTotalDebt;
	public $_mTotalAsset;
	public $_mCompanyNameVi;
	public $_mCompanyNameEn;
	public $_mAddress;
	public $_mPhone;
	public $_mFax;
	public $_mWebsite;
	public $_mIndustryId;
	public $_mHsrr;
	public $_mSoNgayTk;

	public function getId(){
		return $this->_mId;
	}
	public function setId($value){
		$this->_mId = $value;
		return $this;
	}
	public function getCode(){
		return $this->_mCode;
	}
	public function setCode($value){
		$this->_mCode = $value;
		return $this;
	}
	public function getStockExchange(){
		return $this->_mStockExchange;
	}
	public function setStockExchange($value){
		$this->_mStockExchange = $value;
		return $this;
	}
	public function getCurrentPrice(){
		return $this->_mCurrentPrice;
	}
	public function setCurrentPrice($value){
		$this->_mCurrentPrice = $value;
		return $this;
	}
	public function getBookValue(){
		return $this->_mBookValue;
	}
	public function setBookValue($value){
		$this->_mBookValue = $value;
		return $this;
	}
	public function getPB(){
		return $this->_mPB;
	}
	public function setPB($value){
		$this->_mPB = $value;
		return $this;
	}
	public function getHighest52w(){
		return $this->_mHighest52w;
	}
	public function setHighest52w($value){
		$this->_mHighest52w = $value;
		return $this;
	}
	public function getLowest52w(){
		return $this->_mLowest52w;
	}
	public function setLowest52w($value){
		$this->_mLowest52w = $value;
		return $this;
	}
	public function getEPS(){
		return $this->_mEPS;
	}
	public function setEPS($value){
		$this->_mEPS = $value;
		return $this;
	}
	public function getPE(){
		return $this->_mPE;
	}
	public function setPE($value){
		$this->_mPE = $value;
		return $this;
	}
	public function getEPS4q(){
		return $this->_mEPS4q;
	}
	public function setEPS4q($value){
		$this->_mEPS4q = $value;
		return $this;
	}
	public function getPE4q(){
		return $this->_mPE4q;
	}
	public function setPE4q($value){
		$this->_mPE4q = $value;
		return $this;
	}
	public function getROA(){
		return $this->_mROA;
	}
	public function setROA($value){
		$this->_mROA = $value;
		return $this;
	}
	public function getROE(){
		return $this->_mROE;
	}
	public function setROE($value){
		$this->_mROE = $value;
		return $this;
	}
	public function getFinancialLeverage(){
		return $this->_mFinancialLeverage;
	}
	public function setFinancialLeverage($value){
		$this->_mFinancialLeverage = $value;
		return $this;
	}
	public function getBeta(){
		return $this->_mBeta;
	}
	public function setBeta($value){
		$this->_mBeta = $value;
		return $this;
	}
	public function getOutstandingShares(){
		return $this->_mOutstandingShares;
	}
	public function setOutstandingShares($value){
		$this->_mOutstandingShares = $value;
		return $this;
	}
	public function getListedShares(){
		return $this->_mListedShares;
	}
	public function setListedShares($value){
		$this->_mListedShares = $value;
		return $this;
	}
	public function getTreasuryStock(){
		return $this->_mTreasuryStock;
	}
	public function setTreasuryStock($value){
		$this->_mTreasuryStock = $value;
		return $this;
	}
	public function getNuocNgoaiSoHuu(){
		return $this->_mNuocNgoaiSoHuu;
	}
	public function setNuocNgoaiSoHuu($value){
		$this->_mNuocNgoaiSoHuu = $value;
		return $this;
	}
	public function getVonThiTruong(){
		return $this->_mVonThiTruong;
	}
	public function setVonThiTruong($value){
		$this->_mVonThiTruong = $value;
		return $this;
	}
	public function getRevenue(){
		return $this->_mRevenue;
	}
	public function setRevenue($value){
		$this->_mRevenue = $value;
		return $this;
	}
	public function getNPAT(){
		return $this->_mNPAT;
	}
	public function setNPAT($value){
		$this->_mNPAT = $value;
		return $this;
	}
	public function getEquity(){
		return $this->_mEquity;
	}
	public function setEquity($value){
		$this->_mEquity = $value;
		return $this;
	}
	public function getTotalDebt(){
		return $this->_mTotalDebt;
	}
	public function setTotalDebt($value){
		$this->_mTotalDebt = $value;
		return $this;
	}
	public function getTotalAsset(){
		return $this->_mTotalAsset;
	}
	public function setTotalAsset($value){
		$this->_mTotalAsset = $value;
		return $this;
	}
	public function getCompanyNameVi(){
		return $this->_mCompanyNameVi;
	}
	public function setCompanyNameVi($value){
		$this->_mCompanyNameVi = $value;
		return $this;
	}
	public function getCompanyNameEn(){
		return $this->_mCompanyNameEn;
	}
	public function setCompanyNameEn($value){
		$this->_mCompanyNameEn = $value;
		return $this;
	}
	public function getAddress(){
		return $this->_mAddress;
	}
	public function setAddress($value){
		$this->_mAddress = $value;
		return $this;
	}
	public function getPhone(){
		return $this->_mPhone;
	}
	public function setPhone($value){
		$this->_mPhone = $value;
		return $this;
	}
	public function getFax(){
		return $this->_mFax;
	}
	public function setFax($value){
		$this->_mFax = $value;
		return $this;
	}
	public function getWebsite(){
		return $this->_mWebsite;
	}
	public function setWebsite($value){
		$this->_mWebsite = $value;
		return $this;
	}
	public function getIndustryId(){
		return $this->_mIndustryId;
	}
	public function setIndustryId($value){
		$this->_mIndustryId = $value;
		return $this;
	}
	public function getHsrr(){
		return $this->_mHsrr;
	}
	public function setHsrr($value){
		$this->_mHsrr = $value;
		return $this;
	}
	public function getSoNgayTk(){
		return $this->_mSoNgayTk;
	}
	public function setSoNgayTk($value){
		$this->_mSoNgayTk = $value;
		return $this;
	}


	public function setDbTable($dbTable){
		if (is_string($dbTable))
			$dbTable = new $dbTable();
		if (!$dbTable instanceof Zend_Db_Table_Abstract)
			throw new Exception('Invalid table data gateway provided');
		$this->_dbTable = $dbTable;
		return $this;
	}
	public function getDbTable(){
		if (null === $this->_dbTable)
			$this->setDbTable('Application_Model_DbTable_Company');
		return $this->_dbTable;
	}
	public function save(Application_Model_Company $old = null){
		$item = $this;
		$data = array();
		if(isset($item->_mId)) $data['id'] = $item->_mId;
		if(isset($item->_mCode)) $data['code'] = $item->_mCode;
		if(isset($item->_mStockExchange)) $data['stock_exchange'] = $item->_mStockExchange;
		if(isset($item->_mCurrentPrice)) $data['current_price'] = $item->_mCurrentPrice;
		if(isset($item->_mBookValue)) $data['book_value'] = $item->_mBookValue;
		if(isset($item->_mPB)) $data['PB'] = $item->_mPB;
		if(isset($item->_mHighest52w)) $data['highest_52w'] = $item->_mHighest52w;
		if(isset($item->_mLowest52w)) $data['lowest_52w'] = $item->_mLowest52w;
		if(isset($item->_mEPS)) $data['EPS'] = $item->_mEPS;
		if(isset($item->_mPE)) $data['PE'] = $item->_mPE;
		if(isset($item->_mEPS4q)) $data['EPS_4q'] = $item->_mEPS4q;
		if(isset($item->_mPE4q)) $data['PE_4q'] = $item->_mPE4q;
		if(isset($item->_mROA)) $data['ROA'] = $item->_mROA;
		if(isset($item->_mROE)) $data['ROE'] = $item->_mROE;
		if(isset($item->_mFinancialLeverage)) $data['financial_leverage'] = $item->_mFinancialLeverage;
		if(isset($item->_mBeta)) $data['beta'] = $item->_mBeta;
		if(isset($item->_mOutstandingShares)) $data['outstanding_shares'] = $item->_mOutstandingShares;
		if(isset($item->_mListedShares)) $data['listed_shares'] = $item->_mListedShares;
		if(isset($item->_mTreasuryStock)) $data['treasury_stock'] = $item->_mTreasuryStock;
		if(isset($item->_mNuocNgoaiSoHuu)) $data['nuoc_ngoai_so_huu'] = $item->_mNuocNgoaiSoHuu;
		if(isset($item->_mVonThiTruong)) $data['von_thi_truong'] = $item->_mVonThiTruong;
		if(isset($item->_mRevenue)) $data['revenue'] = $item->_mRevenue;
		if(isset($item->_mNPAT)) $data['NPAT'] = $item->_mNPAT;
		if(isset($item->_mEquity)) $data['equity'] = $item->_mEquity;
		if(isset($item->_mTotalDebt)) $data['total_debt'] = $item->_mTotalDebt;
		if(isset($item->_mTotalAsset)) $data['total_asset'] = $item->_mTotalAsset;
		if(isset($item->_mCompanyNameVi)) $data['company_name_vi'] = $item->_mCompanyNameVi;
		if(isset($item->_mCompanyNameEn)) $data['company_name_en'] = $item->_mCompanyNameEn;
		if(isset($item->_mAddress)) $data['address'] = $item->_mAddress;
		if(isset($item->_mPhone)) $data['phone'] = $item->_mPhone;
		if(isset($item->_mFax)) $data['fax'] = $item->_mFax;
		if(isset($item->_mWebsite)) $data['website'] = $item->_mWebsite;
		if(isset($item->_mIndustryId)) $data['industry_id'] = $item->_mIndustryId;
		if(isset($item->_mHsrr)) $data['hsrr'] = $item->_mHsrr;
		if(isset($item->_mSoNgayTk)) $data['so_ngay_tk'] = $item->_mSoNgayTk;

		if($old === null)
			$this->getDbTable()->insert($data);
		else{
			$key = array();
			$old->_mId === null ? $key[] = 'id is NULL' : $key['id = ?'] =  $old->_mId;

			$this->getDbTable()->update($data, $key);
		}
	}
	public function delete(){
		$item = $this;
		$old = $item;
		$key = array();
			$old->_mId === null ? $key[] = 'id is NULL' : $key['id = ?'] =  $old->_mId;

		$this->getDbTable()->delete($key);
	}
	public function fetchAll($where = null, $order = null, $count = null, $offset = null){
		$resultSet = $this->getDbTable()->fetchAll($where, $order, $count, $offset);
		$entries   = array();
		foreach ($resultSet as $row) {
			$item = new Application_Model_Company();
			if(isset($row->id))$item->_mId = $row->id;
			if(isset($row->code))$item->_mCode = $row->code;
			if(isset($row->stock_exchange))$item->_mStockExchange = $row->stock_exchange;
			if(isset($row->current_price))$item->_mCurrentPrice = $row->current_price;
			if(isset($row->book_value))$item->_mBookValue = $row->book_value;
			if(isset($row->PB))$item->_mPB = $row->PB;
			if(isset($row->highest_52w))$item->_mHighest52w = $row->highest_52w;
			if(isset($row->lowest_52w))$item->_mLowest52w = $row->lowest_52w;
			if(isset($row->EPS))$item->_mEPS = $row->EPS;
			if(isset($row->PE))$item->_mPE = $row->PE;
			if(isset($row->EPS_4q))$item->_mEPS4q = $row->EPS_4q;
			if(isset($row->PE_4q))$item->_mPE4q = $row->PE_4q;
			if(isset($row->ROA))$item->_mROA = $row->ROA;
			if(isset($row->ROE))$item->_mROE = $row->ROE;
			if(isset($row->financial_leverage))$item->_mFinancialLeverage = $row->financial_leverage;
			if(isset($row->beta))$item->_mBeta = $row->beta;
			if(isset($row->outstanding_shares))$item->_mOutstandingShares = $row->outstanding_shares;
			if(isset($row->listed_shares))$item->_mListedShares = $row->listed_shares;
			if(isset($row->treasury_stock))$item->_mTreasuryStock = $row->treasury_stock;
			if(isset($row->nuoc_ngoai_so_huu))$item->_mNuocNgoaiSoHuu = $row->nuoc_ngoai_so_huu;
			if(isset($row->von_thi_truong))$item->_mVonThiTruong = $row->von_thi_truong;
			if(isset($row->revenue))$item->_mRevenue = $row->revenue;
			if(isset($row->NPAT))$item->_mNPAT = $row->NPAT;
			if(isset($row->equity))$item->_mEquity = $row->equity;
			if(isset($row->total_debt))$item->_mTotalDebt = $row->total_debt;
			if(isset($row->total_asset))$item->_mTotalAsset = $row->total_asset;
			if(isset($row->company_name_vi))$item->_mCompanyNameVi = $row->company_name_vi;
			if(isset($row->company_name_en))$item->_mCompanyNameEn = $row->company_name_en;
			if(isset($row->address))$item->_mAddress = $row->address;
			if(isset($row->phone))$item->_mPhone = $row->phone;
			if(isset($row->fax))$item->_mFax = $row->fax;
			if(isset($row->website))$item->_mWebsite = $row->website;
			if(isset($row->industry_id))$item->_mIndustryId = $row->industry_id;
			if(isset($row->hsrr))$item->_mHsrr = $row->hsrr;
			if(isset($row->so_ngay_tk))$item->_mSoNgayTk = $row->so_ngay_tk;

			$entries[] = $item;
		}
		return $entries;
	}
}
